#!/usr/bin/ruby

@answer1 = 'Y'
@first = 1
@time = Time.now
while @answer1 == 'Y'
  if @first == 1
    puts "Please enter your first name:"
    @name = gets.chomp
    if @time.hour < 12
      puts "Good Morning " + @name.capitalize + " Welcome to my Concrete Calculator."
    elsif @time.hour > 18
      puts "Good Evening " + @name.capitalize + " Welcome to my Concrete Calculator."
    else
      puts "Good Afternoon " + @name.capitalize + " Welcome to my Concrete Calculator."
    end
    puts ""
  else 
    puts "Welcome back " + @name.capitalize
  end
  @answer2 = 'N'
  @times = 0
  while @answer2 == "N"
    if @times > 0
      puts "Please try harder to enter the correct information!"
    end
    puts "Enter the rate per yard of concrete $ "
    @rate = gets.chomp.to_f
    puts "Enter in feet the length of the area! "
    puts "Example 5 or 5.5: "
    @lNeeded = gets.chomp.to_f
    puts "Enter in feet the width of the area! "
    puts "Example 5 or 5.5: "
    @wNeeded = gets.chomp.to_f
    puts "Enter in inches how thick you want to pour the concrete: "
    @tNeeded = gets.chomp.to_i
    puts "The area you are needing concrete is: " + @lNeeded.to_s + "' x " + 
         @wNeeded.to_s + "' x " + @tNeeded.to_s + "\""
    puts "The cost per yard is $"+ @rate.to_s
    puts "If this information is correct enter a Y for Yes, otherwise enter a N for No. "
    @answer2 = gets.upcase.chomp
    if @answer2 == 'N'  
	@answer3 = 1
    elsif @answer2 == 'Y'
	@answer3 = 1
    else
	@answer3 = 0
    end
    while @answer3 == 0
	puts "Please enter a Y or an N"
	@answer2 = gets.upcase.chomp
	if @answer2 == 'N' || @answer2 == 'Y'
		@answer3 = 1
	end
    end		
    @times += 1
  end
  @thickCoverage = 36.to_f
  @tUnits = @thickCoverage / @tNeeded
  @totUnits = 3.to_f * @tUnits.to_f 
  @tArea = @totUnits.to_f * 3.to_f
  @nArea = @lNeeded * @wNeeded
  @tAmount = (@nArea / @tArea).ceil 
  @cost = @tAmount * @rate
  puts "The area you need to cover is: " + @nArea.to_s + "sq feet x " + 
        @tNeeded.to_s + " inches thick."
  puts "The total amount of concrete you will need is " + @tAmount.to_s + " yard(s)."
  puts""
  puts "The cost for the cement is $" + @cost.to_s
  puts""
  puts "Would you lke to use the calculator again?"
  puts "Enter a Y for YES or an N for NO."
  @answer1 = gets.upcase.chomp
   if @answer1 == 'N'  
	@answer4 = 1
    elsif @answer1 == 'Y'
	@answer4 = 1
    else
	@answer4 = 0
    end
    while @answer4 == 0
	puts "Please enter a Y or an N"
	@answer1 = gets.upcase.chomp
	if @answer1 == 'N' || @answer1 == 'Y'
		@answer4 = 1
	end
    end	
    @first += 1	
end
puts "You have chosen not to use the calculator again."
exit





